package controller;

import java.util.ArrayList;

import pkg.inno.fileshare.R;

import model.ProductItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class SharingExListAdapter extends BaseExpandableListAdapter {

	private Context _context;
	private ArrayList<String> _headerList;
	private ArrayList<ProductItem> _productList;
	
	public SharingExListAdapter(Context context,ArrayList<String> headerList,ArrayList<ProductItem> productList)
	{
		this._context=context;
		this._headerList=headerList;
		this._productList=productList;
	}
	
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		ProductItem obj=_productList.get(groupPosition);
		return obj;
	}

	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) 
	{
		ProductItem prodItem=(ProductItem)getChild(groupPosition, childPosition);
		
		if (convertView==null) 
		{
			LayoutInflater infalInflater=(LayoutInflater)_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=infalInflater.inflate(R.layout.child_row, null);
		}
		TextView sequence = (TextView) convertView.findViewById(R.id.sequence);
		sequence.setText(prodItem.get_productItemId().trim() + ") ");
		TextView childItem = (TextView) convertView.findViewById(R.id.childItem);
		childItem.setText(prodItem.get_productName().trim());
		
		return convertView;
	}

	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return _productList.size();
	}

	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		_headerList.get(groupPosition);
		return null;
	}

	public int getGroupCount() {
		// TODO Auto-generated method stub
		return _headerList.size();
	}

	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) 
	{
		String headerInfo = (String) getGroup(groupPosition);
		  if (convertView == null) 
		  {
		   LayoutInflater inf = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		   convertView = inf.inflate(R.layout.group_heading, null);
		  }
		   
		  TextView heading = (TextView) convertView.findViewById(R.id.heading);
		  heading.setText(headerInfo.trim());
		   
		  return convertView;
	}

	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return true;
	}

	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}

}
